#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLabel>
#include "pushbutton.h"
#include "common.h"

PushButton::PushButton(QWidget *parent) :
    QPushButton(parent)
{
    setStyleSheet("QPushButton{"
                  "border:none; color:rgb(255,255,255);}"
                  "QPushButton:disabled{color:rgb(128,128,128);}"
                  "QPushButton:hover{color:rgb(255,0,0);}"
                  "QPushButton:pressed{color:rgb(255,0,0);};");

    initBg();
}

void PushButton::initBg()
{
    QLabel *lmt = createBglabel("button_bg_top.png");
    lmt->setFixedHeight(2);
    QLabel *lmb = createBglabel("button_bg_bottom.png");
    lmb->setFixedHeight(2);
    QLabel *lmm = new QLabel(this);
    QVBoxLayout *lm = new QVBoxLayout;
    lm->setSpacing(0);
    lm->setContentsMargins(0,0,0,0);
    lm->addWidget(lmt);
    lm->addWidget(lmm);
    lm->addWidget(lmb);

    QLabel *lml = createBglabel("button_bg_left.png");
    lml->setFixedWidth(2);
    QLabel *lmr = createBglabel("button_bg_right.png");
    lmr->setFixedWidth(2);

    QHBoxLayout *layout = new QHBoxLayout;
    layout->setSpacing(0);
    layout->setContentsMargins(0,0,0,0);
    layout->addWidget(lml);
    layout->addLayout(lm);
    layout->addWidget(lmr);
    this->setLayout(layout);
}

QLabel *PushButton::createBglabel(const QString &imgpath)
{
    QLabel *label = new QLabel(this);
    label->setScaledContents(true);
    label->setPixmap(QPixmap(IMG_DIR+imgpath));
    return label;
}
